API Documentation
Public Member Functions | List of all members
nkGraphics::Buffer Class Referenceabstract

A buffer that will reside on the GPU. More...

Inheritance diagram for nkGraphics::Buffer:
nkGraphics::ShaderResource nkExport::Exportable nkGraphics::Resource

Public Member Functions

 Buffer ()
 
 Buffer (const Buffer &other)=delete
 
virtual ~Buffer ()
 
unsigned int getElementByteSize () const
 
unsigned int getElementCount () const
 
unsigned int getTotalByteSize () const
 
virtual USAGE getUsage () const =0
 
virtual BIND_FLAG getBindFlag () const =0
 
virtual CPU_ACCESS_FLAG getCpuAccessFlag () const =0
 
virtual RESOURCE_MISC_FLAG getMiscFlag () const =0
 
void setCpuData (const ResourceCpuDataDescriptor &data)
 
virtual void freeCpuData (bool freeDataPtr)
 
virtual void setElementByteSize (unsigned int value)
 
virtual void setElementCount (unsigned int value)
 
virtual void setUsage (USAGE value)=0
 
virtual void setBindFlag (BIND_FLAG value)=0
 
virtual void setCpuAccessFlag (CPU_ACCESS_FLAG value)=0
 
virtual void setMiscFlag (RESOURCE_MISC_FLAG value)=0
 
virtual void copyParams (const Buffer &other)=0
 
virtual MapResult map (const MapRequestDescriptor &requestDesc)=0
 
virtual void unmap (const UnmapRequestDescriptor &requestDesc)=0
 
virtual void gpuCopyFrom (Buffer &other, const ResourceGpuCopyDescriptor &descriptor)=0
 
virtual void prepareForShaderResourceUsage (bool value=true)
 
virtual void prepareForComputeResourceUsage (bool value=true)
 
virtual void prepareForOutputStreamUsage (bool value=true)
 
Bufferoperator= (const Buffer &other)=delete
 
virtual void exportClassToTree (nkExport::Node *rootNode) override
 
virtual void importClassFromTree (nkExport::Node *rootNode) override
 
- Public Member Functions inherited from nkGraphics::ShaderResource
 ShaderResource ()
 
 ~ShaderResource ()
 
virtual void activate (SHADER_TYPE shaderStage, unsigned int slot)=0
 
- Public Member Functions inherited from nkGraphics::Resource
 Resource ()
 
 Resource (const char *path)
 
virtual ~Resource ()
 
virtual bool load ()=0
 
virtual void unload ()=0
 
bool isReadyForRendering () const
 
bool isUnloaded () const
 
RESOURCE_LOAD_STATE getLoadState () const
 
std::string_view getResourcePath () const
 
RESOURCE_TYPE getResourceTypeName () const
 
std::string_view getResourceName () const
 
bool getHidden () const
 
virtual void setResourcePath (const std::string_view &path)
 
void setResourceName (const std::string_view &name)
 
void setHidden (bool value)
 
- Public Member Functions inherited from nkExport::Exportable
 Exportable ()
 
virtual ~Exportable ()
 

Detailed Description

A buffer that will reside on the GPU.

Used as the basic memory holder to push data to the GPU. Each renderer will have its own implementation to adapt it to the API it targets.

Constructor & Destructor Documentation

◆ Buffer() [1/2]

nkGraphics::Buffer::Buffer ( )

Default Constructor.

◆ Buffer() [2/2]

nkGraphics::Buffer::Buffer ( const Buffer other)
delete

Copy constructor.

◆ ~Buffer()

virtual nkGraphics::Buffer::~Buffer ( )
virtual

Destructor.

Member Function Documentation

◆ getElementByteSize()

unsigned int nkGraphics::Buffer::getElementByteSize ( ) const
Returns
An element's byte size within the buffer.

◆ getElementCount()

unsigned int nkGraphics::Buffer::getElementCount ( ) const
Returns
The element count within the buffer.

◆ getTotalByteSize()

unsigned int nkGraphics::Buffer::getTotalByteSize ( ) const
Returns
The final byte size of the buffer. Computed as elementByteSize * elementCount.

◆ getUsage()

virtual USAGE nkGraphics::Buffer::getUsage ( ) const
pure virtual
Returns
The usage declared for the buffer.

◆ getBindFlag()

virtual BIND_FLAG nkGraphics::Buffer::getBindFlag ( ) const
pure virtual
Returns
The binding declared for the buffer.

◆ getCpuAccessFlag()

virtual CPU_ACCESS_FLAG nkGraphics::Buffer::getCpuAccessFlag ( ) const
pure virtual
Returns
The cpu access flag declared for the buffer.

◆ getMiscFlag()

virtual RESOURCE_MISC_FLAG nkGraphics::Buffer::getMiscFlag ( ) const
pure virtual
Returns
Any misc flag set on the buffer.

◆ setCpuData()

void nkGraphics::Buffer::setCpuData ( const ResourceCpuDataDescriptor data)

Sets the CPU data to upload to the gpu buffer.

Parameters
dataA description of the data to upload.

◆ freeCpuData()

virtual void nkGraphics::Buffer::freeCpuData ( bool  freeDataPtr)
virtual

Frees the CPU data holding structures within the gpu buffer.

Parameters
freeDataPtrIf the data provided by the external code should be freed or not.
Remarks
Renderers are smart enough to know when data should be freed. After a call to load(), this function can be called right away and the buffer will delete it when it can.

◆ setElementByteSize()

virtual void nkGraphics::Buffer::setElementByteSize ( unsigned int  value)
virtual

Sets the size of an element within the buffer.

Parameters
valueThe byte size an element will have in the buffer.

◆ setElementCount()

virtual void nkGraphics::Buffer::setElementCount ( unsigned int  value)
virtual

Sets the number of elements inside the buffer.

Parameters
valueThe number of elements to declare inside the buffer.

◆ setUsage()

virtual void nkGraphics::Buffer::setUsage ( USAGE  value)
pure virtual

Sets the usage flag in the buffer.

Parameters
valueThe usage flag to declare.
Remarks
Not to be confused with declaring what usage will be done within the API with the buffer.

◆ setBindFlag()

virtual void nkGraphics::Buffer::setBindFlag ( BIND_FLAG  value)
pure virtual

Sets the binding flags for the buffer.

Parameters
valueThe binding flag to declare.

◆ setCpuAccessFlag()

virtual void nkGraphics::Buffer::setCpuAccessFlag ( CPU_ACCESS_FLAG  value)
pure virtual

Sets the cpu access flags for the buffer.

Parameters
valueThe value to declare.

◆ setMiscFlag()

virtual void nkGraphics::Buffer::setMiscFlag ( RESOURCE_MISC_FLAG  value)
pure virtual

Sets the misc flags for the buffer.

Parameters
valueThe value to declare.

◆ copyParams()

virtual void nkGraphics::Buffer::copyParams ( const Buffer other)
pure virtual

Copies the parameters from another buffer.

Parameters
otherThe buffer to copy the parameters from.

◆ map()

virtual MapResult nkGraphics::Buffer::map ( const MapRequestDescriptor requestDesc)
pure virtual

Maps the buffer. This allows to read or write the GPU data from the cpu context. For a read request, depending on the usage and CPU access flag, this can trigger staging buffer creation and copy to pull data from the GPU. Note that in some cases, this means a flush in the GPU pipeline (and a CPU lock) to ensure the latest data is retrieved.

Parameters
requestDescThe description of what kind of mapping is needed.
Returns
The resulting mapped memory, if the request is valid. If not, reason will be logged, and mapped memory will be nullptr.
Remarks
At all times, a buffer can only be mapped once. Be sure to call unmap() once the map handle is not necessary anymore.

◆ unmap()

virtual void nkGraphics::Buffer::unmap ( const UnmapRequestDescriptor requestDesc)
pure virtual

Requests to unmap the buffer. Should be called the earliest possible after a call to map().

Parameters
requestDescThe description of the unmap request.

◆ gpuCopyFrom()

virtual void nkGraphics::Buffer::gpuCopyFrom ( Buffer other,
const ResourceGpuCopyDescriptor descriptor 
)
pure virtual

Copy memory from one buffer to another. This will trigger copies on GPU, and involve the CPU the least possible.

Parameters
otherThe buffer to copy from.
descriptorThe description of what kind of copy is wanted.
Remarks
Special care needs to be taken to ensure that a copy is possible between both resources.

◆ prepareForShaderResourceUsage()

virtual void nkGraphics::Buffer::prepareForShaderResourceUsage ( bool  value = true)
virtual

Prepares the resource for an usage as a shader resource. This is needed to use the buffer in a Shader::addTexture() call.

Parameters
valueIf the buffer should be usable in such context (true) or not (false).

◆ prepareForComputeResourceUsage()

virtual void nkGraphics::Buffer::prepareForComputeResourceUsage ( bool  value = true)
virtual

Prepares the resource for an usage as a compute resource. This is needed to use the buffer in a Shader::addUavBuffer() call.

Parameters
valueIf the buffer should be usable in such context (true) or not (false).

◆ prepareForOutputStreamUsage()

virtual void nkGraphics::Buffer::prepareForOutputStreamUsage ( bool  value = true)
virtual

Prepares the resource for an usage as an output stream resource. This is needed to use the buffer in a Renderer::launchGeometryShaderStream() call.

Parameters
valueIf the buffer should be usable in such context (true) or not (false).

◆ operator=()

Buffer& nkGraphics::Buffer::operator= ( const Buffer other)
delete

Copy operator.

◆ exportClassToTree()

virtual void nkGraphics::Buffer::exportClassToTree ( nkExport::Node rootNode)
overridevirtual

Basic export capability.

Parameters
rootNodeThe root of the tree to export to.

Implements nkExport::Exportable.

◆ importClassFromTree()

virtual void nkGraphics::Buffer::importClassFromTree ( nkExport::Node rootNode)
overridevirtual

Basic import capability.

Parameters
rootNodeThe root of the tree to import from.

Implements nkExport::Exportable.


The documentation for this class was generated from the following file: